package com.cloud.test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author DELL
 * @WebServlet 注解使浏览器得知要调用的servlet类的名称
 *             若使用servlet的html对象不直接在web目录下，则需要添加路径名
 * 当action触发，若无doPost方法或doGet方法，service 方法默认启动(service方法中判断method属于什么类型，并且调用相应方法)
 *
 */
@WebServlet(value = {"/Test01","/test01"}, name = "Servlet01")
public class ServletTest01 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().write("Hello,servlet");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Hello,servlet!");
        //getWrite function return a PrintWrite to print data to our browser.
        resp.getWriter().write("Hello,servlet");
    }
}
